package com.ruoyi.asset.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.asset.domain.PropertyAsset;
import com.ruoyi.asset.service.IPropertyAssetService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物业资产Controller
 * 
 * @author ruoyi
 * @date 2025-10-27
 */
@RestController
@RequestMapping("/asset/asset")
public class PropertyAssetController extends BaseController
{
    @Autowired
    private IPropertyAssetService propertyAssetService;

    /**
     * 查询物业资产列表
     */
    @PreAuthorize("@ss.hasPermi('asset:asset:list')")
    @GetMapping("/list")
    public TableDataInfo list(PropertyAsset propertyAsset)
    {
        startPage();
        List<PropertyAsset> list = propertyAssetService.selectPropertyAssetList(propertyAsset);
        return getDataTable(list);
    }

    /**
     * 导出物业资产列表
     */
    @PreAuthorize("@ss.hasPermi('asset:asset:export')")
    @Log(title = "物业资产", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PropertyAsset propertyAsset)
    {
        List<PropertyAsset> list = propertyAssetService.selectPropertyAssetList(propertyAsset);
        ExcelUtil<PropertyAsset> util = new ExcelUtil<PropertyAsset>(PropertyAsset.class);
        util.exportExcel(response, list, "物业资产数据");
    }

    /**
     * 获取物业资产详细信息
     */
    @PreAuthorize("@ss.hasPermi('asset:asset:query')")
    @GetMapping(value = "/{assetId}")
    public AjaxResult getInfo(@PathVariable("assetId") Long assetId)
    {
        return success(propertyAssetService.selectPropertyAssetByAssetId(assetId));
    }

    /**
     * 新增物业资产
     */
    @PreAuthorize("@ss.hasPermi('asset:asset:add')")
    @Log(title = "物业资产", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PropertyAsset propertyAsset)
    {
        return toAjax(propertyAssetService.insertPropertyAsset(propertyAsset));
    }

    /**
     * 修改物业资产
     */
    @PreAuthorize("@ss.hasPermi('asset:asset:edit')")
    @Log(title = "物业资产", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PropertyAsset propertyAsset)
    {
        return toAjax(propertyAssetService.updatePropertyAsset(propertyAsset));
    }

    /**
     * 删除物业资产
     */
    @PreAuthorize("@ss.hasPermi('asset:asset:remove')")
    @Log(title = "物业资产", businessType = BusinessType.DELETE)
	@DeleteMapping("/{assetIds}")
    public AjaxResult remove(@PathVariable Long[] assetIds)
    {
        return toAjax(propertyAssetService.deletePropertyAssetByAssetIds(assetIds));
    }
}
